<template>
    <div class="box">
           <Header :headerTxt="$t('ws_assets.team')" :showBack="true"></Header>
            <div class="content">
              <el-tree
                  :data="treeData"
                  :props="defaultProps"
                  accordion
                  @node-click="handleNodeClick">
                </el-tree>
            </div>
    </div>
</template>
<script>
import Header from "../../components/Header";
import { geteam } from '@/api/getData'
export default {
    components: { Header },
    data() {
      return {
        user:JSON.parse(sessionStorage.getItem("user")),
        data: [],
        defaultProps: {
          children: 'children',
          label: 'user_id'
        }
      };
    },
	created(){
		this.geteam();
	},
	computed:{
		treeData(){
		  let cloneData = JSON.parse(JSON.stringify(this.data))    // 对源数据深度克隆
		  return cloneData.filter(father=>{               
			let branchArr = cloneData.filter(child=>father.user_id == child.othcode)    //返回每一项的子级数组
			branchArr.length>0 ? father.children = branchArr : ''   //如果存在子级，则给父级添加一个children属性，并赋值
			return father.othcode==0;      //返回第一层
		  });
		}
	  },
	methods:{
        handleNodeClick(data){
        },
    async getData(){
        let pare = {"user_id":this.user.user_id}
        const res = await geteam(pare);
        this.data = res.data.result.children;
    },
      },
      mounted(){
        this.getData();
      },
};
</script>
<style scoped>
  .el-tree{
    margin-top: 1.0rem;
    min-height: 70vh;
    font-size: 17px;
  }
  .el-tree-node is-focusable{
    height:1rem;
  }
</style>